#include "FLASH.h"

void WriteDataToFlash_int16(int16_t *data, uint16_t length) {
    FLASH_Unlock();
    FLASH_ErasePage(PANG_63_START_ADDRESS);
    for (uint16_t i = 0; i < length; i++) {
        FLASH_ProgramHalfWord(PANG_63_START_ADDRESS + i * 2, (uint16_t)data[i]);
    }
    FLASH_Lock();
}

void ReadDataFromFlash_int16(int16_t *data, uint16_t length) {
    for (uint16_t i = 0; i < length; i++) {
        data[i] = (int16_t)(*(__IO uint16_t *)(PANG_63_START_ADDRESS + i * 2));
    }
}

void WriteDataToFlash_float(float *data, uint16_t length) {
    FLASH_Unlock();
    FLASH_ErasePage(PANG_64_START_ADDRESS);
    for (uint16_t i = 0; i < length; i++) {
        FLASH_ProgramWord(PANG_64_START_ADDRESS + i * 4, *(uint32_t *)&data[i]);
    }
    FLASH_Lock();
}

void ReadDataFromFlash_float(float *data, uint16_t length) {
    for (uint16_t i = 0; i < length; i++) {
        data[i] = *(float *)(PANG_64_START_ADDRESS + i * 4);
    }
}